/*     */ package com.newcrm.db;
/*     */ 
/*     */ import com.newcrm.exception.DBException;
/*     */ import java.sql.Connection;
/*     */ import java.sql.SQLException;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.dbutils.DbUtils;
/*     */ import org.apache.commons.dbutils.GenKeyQueryRunner;
/*     */ import org.apache.commons.dbutils.MyMapListHandler;
/*     */ import org.apache.commons.dbutils.QueryRunner;
/*     */ import org.apache.commons.dbutils.handlers.ScalarHandler;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class ExportTaskManager
/*     */ {
/*  26 */   private static Logger logger = Logger.getLogger(ExportTaskManager.class
/*  27 */     .getName());
/*     */ 
/*     */   public int add(int companyId, String Subject, int num, Object user, Object customerSearchCondition, String filePath, String userId)
/*     */     throws DBException, SQLException
/*     */   {
/*  46 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  47 */     if (conn == null) {
/*  48 */       throw new DBException();
/*     */     }
/*  50 */     GenKeyQueryRunner runner = new GenKeyQueryRunner(
/*  51 */       new ScalarHandler(), new String[] { "ExportTaskId" });
/*     */     try {
/*  53 */       runner.update(conn, "INSERT INTO T_ExportTask_Info (StartDate, Subject, TotalNum, UserObject,CustomerSearchConditionObject,FilePath,CompanyId,UserId,IsFinish,ExportNum) VALUES (NOW(), ?,?,?,?,?,?,?,0,0)", new Object[] { Subject, Integer.valueOf(num), user, 
/*  54 */         customerSearchCondition, filePath, Integer.valueOf(companyId), userId });
/*  55 */       return ((Long)runner.getGeneratedKeys()).intValue();
/*     */     } finally {
/*     */       try {
/*  58 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  60 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int delete(int exportTaskId, String UserId)
/*     */   {
/*  73 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  74 */     if (conn == null) {
/*  75 */       return 0;
/*     */     }
/*  77 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/*  79 */       return runner.update(conn, "DELETE FROM T_ExportTask_Info WHERE ExportTaskId = ? AND IsFinish = 0 AND UserId = ?", new Object[] { 
/*  80 */         Integer.valueOf(exportTaskId), UserId });
/*     */     } catch (Exception e) {
/*  82 */       logger.warn("delete export task failed", e);
/*     */     } finally {
/*     */       try {
/*  85 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  87 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*  90 */     return 0;
/*     */   }
/*     */ 
/*     */   public int updateExportNum(Connection conn, int exportTaskId, int exportNum)
/*     */   {
/* 101 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 103 */       return runner.update(conn, "UPDATE T_ExportTask_Info SET ExportNum = ? WHERE ExportTaskId = ?", new Object[] { Integer.valueOf(exportNum), 
/* 104 */         Integer.valueOf(exportTaskId) });
/*     */     } catch (Exception e) {
/* 106 */       logger.warn("update export num failed", e);
/*     */     }
/* 108 */     return 0;
/*     */   }
/*     */ 
/*     */   public int setFinish(Connection conn, int exportTaskId, int exportNum)
/*     */   {
/* 119 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/* 122 */       return runner.update(conn, "UPDATE T_ExportTask_Info SET ExportNum = ?, EndDate = NOW(), IsFinish = 1 WHERE ExportTaskId = ?", new Object[] { Integer.valueOf(exportNum), 
/* 123 */         Integer.valueOf(exportTaskId) });
/*     */     } catch (Exception e) {
/* 125 */       logger.warn("update export num failed", e);
/*     */     }
/* 127 */     return 0;
/*     */   }
/*     */ 
/*     */   public List<Map<String, Object>> list(int offset, int companyId, String userId)
/*     */     throws DBException
/*     */   {
/* 140 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 141 */     if (conn == null) {
/* 142 */       return null;
/*     */     }
/*     */ 
/* 145 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 147 */       StringBuffer sql = new StringBuffer("SELECT ExportTaskId,StartDate,Subject,TotalNum,ExportNum,FilePath,IsFinish FROM T_ExportTask_Info WHERE CompanyId = ? AND UserId = ? ORDER BY ExportTaskId DESC ");
/* 148 */       sql.append(" LIMIT ").append(offset).append(", ")
/* 149 */         .append(10);
/*     */ 
/* 151 */       return (List)runner.query(conn, sql.toString(), new MyMapListHandler(), new Object[] { 
/* 152 */         Integer.valueOf(companyId), userId });
/*     */     } catch (SQLException e) {
/* 154 */       throw new DBException();
/*     */     } finally {
/*     */       try {
/* 157 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 159 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */   }
/*     */ 
/*     */   public int getTotalNum(int companyId, String userId)
/*     */   {
/* 172 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 173 */     if (conn == null) {
/* 174 */       return 0;
/*     */     }
/*     */ 
/* 177 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/* 179 */       Object obj = runner.query(conn, "SELECT COUNT(*) FROM T_ExportTask_Info WHERE CompanyId = ? AND UserId = ?", 
/* 180 */         new ScalarHandler(1), new Object[] { Integer.valueOf(companyId), userId });
/* 181 */       if (!(obj instanceof Long)) {
/* 182 */         return 0;
/*     */       }
/* 184 */       return ((Long)obj).intValue();
/*     */     } catch (SQLException e) {
/* 186 */       logger.warn("get count failed", e);
/*     */     } finally {
/*     */       try {
/* 189 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 191 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 194 */     return 0;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.ExportTaskManager
 * JD-Core Version:    0.6.1
 */